import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import routes from './router'
import store from '@/store'
// import '@/plugins/rem'
import '@/style/common.scss'
import 'amfe-flexible'

// 全局配置时间过滤器
import '@/plugins/dayjs'


import { NavBar, Toast, Tabbar, TabbarItem, Icon, Search, Button, Tab, Tabs, Popup, Cell, CellGroup, Checkbox, CheckboxGroup, Divider, Field, Form, CountDown, Image as VanImage, Grid, GridItem, Dialog, Picker, DatetimePicker, List, PullRefresh, Loading } from 'vant'
Vue.use(Popup)
Vue.use(NavBar)
Vue.use(Toast)
Vue.use(Tabbar)
Vue.use(TabbarItem)
Vue.use(VueRouter)
Vue.use(Icon)
Vue.use(Search)
Vue.use(Button)
Vue.use(Tab)
Vue.use(Tabs)
Vue.use(Cell)
Vue.use(CellGroup)
Vue.use(Checkbox)
Vue.use(CheckboxGroup)
Vue.use(Divider)
Vue.use(Field)
Vue.use(Form)
Vue.use(CountDown)
Vue.use(VanImage)
Vue.use(Grid)
Vue.use(GridItem)
Vue.use(Dialog)
Vue.use(Picker)
Vue.use(DatetimePicker)
Vue.use(List)
Vue.use(PullRefresh)
Vue.use(Loading)
Vue.config.productionTip = false
const router = new VueRouter({
    routes, // 所有的路由组件都要执行
    mode: 'hash', // 路由模式
    strict: process.env.NODE_ENV !== 'production',
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            // 判断当前页面是否有缓存数据
            if (from.meta.keepAlive) {
                from.meta.savedPosition = document.body.scrollTo
            }
            // 如果要跳转到的页面也有页面缓存的话，返回的是页面缓存的数据
            return { x: 0, y: to.meta.savedPosition || 0 }
        }
    }
})

new Vue({
    router,
    store,
    render: h => h(App),
}).$mount('#app')
